#!/usr/bin/php
<?php

/**
 * Test script for FineDB.
 *
 * @author	Amaury Bouchard <amaury.bouchard@finemedia.fr>
 * @copyright	Copyright (c) 2010, FineMedia
 * @package	FineDB
 * @subpackage	test
 */

require_once("../lib/php/class.FineDB.php");
require_once("../lib/php/class.FineDBDocument.php");

// DB connection
$base = new FineDb("test");

// collection creation
$indexes = array(
	'email'		=> "unique",
	'nickname'	=> "multiple",
	'gender'	=> "multiple"
);
$mandatory = array(
	"login",
	"email"
);
$users = $base->createCollection("users", $indexes, $mandatory);

// user creation
$meta = array(
	'login'		=> "john",
	'email'		=> "john@john.com",
	'gender'	=> "male",
	'nickname'	=> array(
		"Johnny", "James"
	)
);
$data = array(
	'name'		=> "Mister John",
	'messages'	=> array(
		"I like flowers",
		"I hate plastic flowers"
	)
);
$user = $users->add($data, $meta);

// user creation
$meta = array(
	'login'		=> "bob",
	'email'		=> "bob@bob.com",
	'gender'	=> "male",
	'nickname'	=> array(
		"Bobu", "Bobo", "James"
	)
);
$data = array(
	'name'		=> "Mister Bob",
	'messages'	=> array(
		"I'm a Linux user",
		"I was a NetBSD user"
	)
);
$user = $users->add($data, $meta);

// user creation
$meta = array(
	'login'		=> "lynda",
	'email'		=> "lynda@lynda.com",
	'gender'	=> "female"
);
$data = array(
	'name'		=> "Miss Lynda",
	'messages'	=> array(
		"I'm the third user"
	)
);
$user = $users->add($data, $meta);
$user->setMeta("email", "lyn@da.com");
$user->save();

?>
